package com.csgc.camera.widget.dialog.adapter

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import androidx.viewpager.widget.ViewPager

import com.csgc.camera.util.clickWithTrigger
import com.csgc.camera.widget.RecyclerTabLayout
import com.cysd.spsyxj.R
import com.cysd.spsyxj.databinding.ItemMaskTabBinding


class MaskTabAdapter(val context:Context,val list:ArrayList<String>,viewPager: ViewPager): RecyclerTabLayout.Adapter<MaskTabAdapter.MaskTabHolder>(viewPager) {

    fun updateData(datas:List<String>){
        list.clear()
        list.addAll(datas)
        notifyDataSetChanged()
    }
    private val defaultColor:Int by lazy {
        ContextCompat.getColor(context, R.color.color_999999)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MaskTabHolder {
        return MaskTabHolder(ItemMaskTabBinding.inflate(LayoutInflater.from(context),parent,false))
    }

    override fun onBindViewHolder(holder: MaskTabHolder, position: Int) {
        val data = list[position]
        holder.binding.apply {
            if(viewPager.currentItem == position){
                tvTabName.setTextColor(Color.BLACK)
            }else{
                tvTabName.setTextColor(defaultColor)
            }
            tvTabName.text = data
            root.clickWithTrigger {
                if(viewPager.currentItem != position){
                    viewPager.currentItem = position
                }

            }
        }

    }

    override fun getItemCount(): Int {
        return list.size
    }

    inner class MaskTabHolder(val binding:ItemMaskTabBinding):ViewHolder(binding.root)
}